package com.dq.utils;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/***
 * 分页工具类
 */

public class PageableUtil {

    public static final Pageable get(Integer page, Integer size) {
        if (null == page || page < 1) page = 1;
        if (null == size) size = 10;
        return PageRequest.of(page-1, size);
    }

    public static final Pageable get(Integer page, Integer size, boolean isAsc, String sortField) {
        if (null == page || page < 0) page = 1;
        if (null == size) size = 10;
        Sort.Direction direction = isAsc ? Sort.Direction.ASC : Sort.Direction.DESC;
        return PageRequest.of(page-1, size, direction, sortField);
    }
}
